Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Porting: auth module #3

Merged
merged 77 commits into from
Apr 8, 2024
Merged

Porting: auth module #3

merged 77 commits into from
Apr 8, 2024

Conversation

marcello33
Copy link
Collaborator

This PR is a first attempt to port the auth module implementation from heimdall to cosmos-sdk.

Please, pay particular attention to the comments starting with prefix TODO HV2, as they define open points that need action within this PR, or later on (once other modules are implemented).

I would recommend reviewing everything under x/auth... first, as there are also editions to other modules/packages of cosmos-sdk.
Such changes are made with the only purpose to be able to build the overall project.
For example, wrt the change from bech32 to hex, the tests have been fixed in auth module, but it may happen that in other modules you still see bech32 prefixes/addresses being used, despite the underlying codec/methods are hex based. Those occurrences/tests will be fixed when such modules will be considered for implementation/porting, or at the end of the migration process.

Raneet10 and others added 27 commits December 19, 2023 14:00
* resolved todos in keeper.go (except 1)

* updated x/auth/keeper/grpc_query.go with comments

* added comments in auth/module.go

* removed depinject from auth.ModuleInputs

* resolved TODOs in auth/keeper/genesis (created NewBaseAccount and passed to processor)

* removed some TODOs from x/auth/types/account.go

* added few comments in x/auth/ante/ante.go

* few final comments and modifications
Copy link

@marcello33 your pull request is missing a changelog!

Copy link
Collaborator

@sergio-mena sergio-mena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made an extra pass, checking latest changes. LGTM

x.Key = value.Bytes()
default:
if fd.IsExtension() {
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.crypto.secp256k1.PubKeyOld"))

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
if fd.IsExtension() {
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.crypto.secp256k1.PubKeyOld"))
}
panic(fmt.Errorf("message cosmos.crypto.secp256k1.PubKeyOld does not contain field %s", fd.FullName()))

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
x.Key = value.Bytes()
default:
if fd.IsExtension() {
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.crypto.secp256k1.PubKey"))

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
if fd.IsExtension() {
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.crypto.secp256k1.PubKey"))
}
panic(fmt.Errorf("message cosmos.crypto.secp256k1.PubKey does not contain field %s", fd.FullName()))

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
x.Key = value.Bytes()
default:
if fd.IsExtension() {
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.crypto.secp256k1.PubKey"))
panic(fmt.Errorf("proto3 declared messages do not support extensions: cosmos.crypto.secp256k1.PrivKeyOld"))

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
}
panic(fmt.Errorf("message cosmos.crypto.secp256k1.PubKey does not contain field %s", fd.FullName()))
panic(fmt.Errorf("message cosmos.crypto.secp256k1.PrivKeyOld does not contain field %s", fd.FullName()))

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
func (pubKey *PubKey) Address() crypto.Address {
if len(pubKey.Key) != PubKeySize {
panic("length of pubkey is incorrect")
panic(fmt.Sprintf("length of pubkey is incorrect %d != %d", len(pubKey.Key), PubKeySize))

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
@@ -164,7 +164,7 @@
// in SDK except in a tendermint validator context.
func (pubKey *PubKey) Address() crypto.Address {
if len(pubKey.Key) != PubKeySize {
panic("pubkey is incorrect size")
panic(fmt.Sprintf("length of pubkey is incorrect %d != %d", len(pubKey.Key), PubKeySize))

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
// Address returns an ethereum style addresses
func (pubKey *PubKeyOld) Address() crypto.Address {
if len(pubKey.Key) != PubKeySize {
panic(fmt.Sprintf("length of pubkey is incorrect %d != %d", len(pubKey.Key), PubKeySize))

Check warning

Code scanning / CodeQL

Panic in BeginBock or EndBlock consensus methods Warning

Possible panics in BeginBock- or EndBlock-related consensus methods could cause a chain halt
if len(strings.TrimSpace(text)) == 0 {
return []byte{}, errors.New("empty address string is not allowed")
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make a check for exact length of address?

Copy link
Collaborator Author

@marcello33 marcello33 Mar 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is done already by VerifyAddressFormat, specifically by common.IsHexAddress

if len(bz) == 0 || bz == nil {
return "", nil
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also check for bytes length?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would not be useful, as - once translated to string - it will be done by VerifyAddressFormat, specifically by common.IsHexAddress

@@ -10,7 +10,7 @@ import (

"github.com/cometbft/cometbft/crypto"
secp256k1 "github.com/decred/dcrd/dcrec/secp256k1/v4"
"golang.org/x/crypto/ripemd160" //nolint: staticcheck // keep around for backwards compatibility
ethCrypto "github.com/ethereum/go-ethereum/crypto" //nolint:depguard

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we keep this for easy upstream or no need?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ripemd160 is no longer used, so no need to keep it.
ethCrypto is there of course.

@@ -0,0 +1,50 @@
package codec

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this file is defined again?
Can't we the Hexcodex we defined earlier?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To keep our fork as close as possible to upstream.
It is exactly the same in cosmos, where bech32 codec is defined in the codec package, but also at modules' level

anteDecorators := []sdk.AnteDecorator{
ante.NewSetUpContextDecorator(), // outermost AnteDecorator. SetUpContext must be called first
circuitante.NewCircuitBreakerDecorator(options.CircuitKeeper),
ante.NewExtensionOptionsDecorator(options.ExtensionOptionChecker),
ante.NewValidateBasicDecorator(),
ante.NewTxTimeoutHeightDecorator(),
// ante.NewTxTimeoutHeightDecorator(),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we removed this? Though it is not there in Heimdall but can it be useful to us?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the purpose of only preserving only the heimdall changes, I removed everything which was not there.
Maybe we can investigate this functionality and enable it afterwards. Wdyt? In case, I'll create a JIRA task.

NewTxTimeoutHeightDecorator(),
NewValidateMemoDecorator(options.AccountKeeper),
// NewTxTimeoutHeightDecorator(), // HV2: this is not present in heimdall. Is it safe to remove?
NewValidateMemoDecorator(options.AccountKeeper), // TODO HV2: can we keep this despite we don't support Memo? Or is it better/safer to remove it?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Memo don't have any impact on tx logic, right? But it may increase the size of transaction.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. But I checked, and it's in heimdall-v1 too, that's why I kept it.

// if ctx.BlockHeight() < helper.GetAalborgHardForkHeight() && (stdTx.Msg.Type() == checkpointTypes.EventTypeMilestone || stdTx.Msg.Type() == checkpointTypes.EventTypeMilestoneTimeout) {
// newCtx = SetGasMeter(simulate, ctx, 0)
// return newCtx, sdk.ErrTxDecode("error decoding transaction").Result(), true
// }

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can remove this comment, any hard fork is not required as we are starting a new chain.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done here

marcello33 and others added 5 commits March 18, 2024 14:29
* add: port gov module

* chg: implement WeightedVoteOptions with constraints

* chg: better TODOs descriptions

* chg: POS-2135: fix some tests

* chg: POS-2135: fix more tests

* chg: POS-2135: update an address format

* chg: fix few more tests

* chg: fix few more tests

* chg: fix some tests / temp revert some others to properly tune params later on

* chg: fix TestHooks

* chg: fix burn related methods / fix tests

* chg: fix query for WeightedVoteOptions / better comments

* chg: fix all tests in gov module

* chg: fix a staking integration test

* chg: POS-2142: edit gov readme

* chg: use AccAddressFromHex in tests instead of addressCodec

* chg: enable one test / provide better context for the only skipped test

* chg: use hex acc addresses in gov tests

* chg: return empty string on ProposalType normalization

* chg: remove TextProposals / add comment for Msgs auto-execution

* chg: re-enable textProposals / TBD with team

* chg: remove comment

* chg: better context for HV2 TODOs

* chg: filter out non valid proposals msgs types and content

* chg: fix typeUrls

* chg: filter out not supported messages at time of proposals submit / fix tests accordingly

* chg: go mod tidy

* chg: address PR comments: filtering dedicated file / test msg types / edit comments

* chg: register interfaces in gov test app

* chg: better context for comments

* chg: comment for future improvements

* chg: consistent example of gov tx for submit proposal

* chg: add msgServers in testApp to allow additional MsgUpdateParams types

* chg: fix tests after merge

* chg: update go deps for sdk and simapp

* chg: comment

* chg: comment in README for further actions

---------

Co-authored-by: Raneet Debnath <[email protected]>
* proto,x/bank: initial port of heimdall related changes for bank module

* x/bank: rm moduleName param from SubtractCoins + rm MsgSetSendEnabled,add MsgMultiSend to amino registry + rm unused commented code

* simapp,x/auth,x/bank: address PR comments

* x/bank: change feeAmount to defaultFeeAmount in test

* x/bank: address PR comments

* x/bank: use CreateRandomValidatorSet instead of manually initialising validator set in tests

* x/bank,proto: change heimdall v2 comment format

* all: fix broken simapp dep

* x/bank: rm SetCoins

* x/auth,x/bank: modify bank tests with assertions for fee_collector and account balances

* x/bank: minor code refactors
@marcello33 marcello33 merged commit 11853a3 into devel Apr 8, 2024
7 of 40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants